#!/usr/bin/python2
# -*- coding: utf-8 -*-

'''
Knowtemarks
===========
A simple tool to manage your notes and bookmarks

@author: Markus Fuchs, 2012
'''

import knowtemarks.config as c
from knowtemarks.web.handler.Default import MainHandler, AddHandler, SearchHandler, BrowseHandler, \
    ImportHandler, DeleteHandler, NotFoundHandler
from knowtemarks.web.handler.Ajax import AjaxHandler
from tornado.web import StaticFileHandler
import tornado.ioloop
import tornado.web

if __name__ == '__main__':
    log = c.log
    application = tornado.web.Application([
        (r"/static/(.*)", StaticFileHandler, {"path": c.staticDir }),
        (r"/", MainHandler, dict(knowteDao=c.kdao)),
        (r"/a/(add|edit|delete)+(/(.*))*", AjaxHandler, dict(knowteDao=c.kdao)),
        (r"/add", AddHandler, dict(knowteDao=c.kdao)),
        (r"/delete/(.*)", DeleteHandler, dict(knowteDao=c.kdao)),
        (r"/search", SearchHandler, dict(knowteDao=c.kdao)),
        (r"/import", ImportHandler, dict(knowteDao=c.kdao)),
        (r"(/notes|/bm|/b)*(/t/(.*))*", BrowseHandler, dict(knowteDao=c.kdao)),
        (r"/(.*)", NotFoundHandler, dict(knowteDao=c.kdao)),
    ], template_path=c.templateDir)
    
    log.info("Listening on port %d..." % c.port)
    application.listen(c.port)
    tornado.ioloop.IOLoop.instance().start()